<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recordDate">
              <j-date placeholder="请选择日期" v-model="model.recordDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="班级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classId">
              <j-dict-select-tag type="list" v-model="model.classId" dictCode="sk_class,class_name,id,del_flag = 0 order by sort_no asc" placeholder="请选择班级" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="室内空气" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="air">
              <j-dict-select-tag type="radio"  v-model="model.air" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="餐具" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tableware">
              <j-dict-select-tag type="radio"  v-model="model.tableware" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="水杯" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cup">
              <j-dict-select-tag type="radio"  v-model="model.cup" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毛巾类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="towel">
              <j-dict-select-tag type="radio"  v-model="model.towel" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="抹布" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dusterCloth">
              <j-dict-select-tag type="radio"  v-model="model.dusterCloth" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="餐桌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="diningTable">
              <j-dict-select-tag type="radio"  v-model="model.diningTable" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="门、门把手" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="door">
              <j-dict-select-tag type="radio"  v-model="model.door" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="水龙头" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faucet">
              <j-dict-select-tag type="radio"  v-model="model.faucet" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="拖把" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mop">
              <j-dict-select-tag type="radio"  v-model="model.mop" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="厕所地面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toiletFloor">
              <j-dict-select-tag type="radio"  v-model="model.toiletFloor" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="室内地面" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roomFloor">
              <j-dict-select-tag type="radio"  v-model="model.roomFloor" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="床铺被褥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bed">
              <j-dict-select-tag type="radio"  v-model="model.bed" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="玩具" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toy">
              <j-dict-select-tag type="radio"  v-model="model.toy" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="book">
              <j-dict-select-tag type="radio"  v-model="model.book" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="便盆坐便" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bedPan">
              <j-dict-select-tag type="radio"  v-model="model.bedPan" dictCode="yn" placeholder="请选择是否消毒" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TbDisinfectRecordTableForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          air:"0",
          tableware:"0",
          cup:"0",
          towel:"0",
          dusterCloth:"0",
          diningTable:"0",
          door:"0",
          faucet:"0",
          mop:"0",
          toiletFloor:"0",
          roomFloor:"0",
          bed:"0",
          toy:"0",
          tabbookleware:"0",
          book:"0",
          bedPan:"0"
        },
        keyList:["air","tableware","cup","towel","dusterCloth","diningTable","door","faucet","mop","toiletFloor","roomFloor","bed","toy","book","bedPan"],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          classId: [
            { required: true, message: '请选择班级!'},
          ],
          recordDate: [
            { required: true, message: '请选择日期!'},
          ],
        },
        url: {
          add: "/table/tbDisinfectRecordTable/add",
          edit: "/table/tbDisinfectRecordTable/edit",
          queryById: "/table/tbDisinfectRecordTable/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        // if (!this.model.id) {
        //   this.keyList.forEach(item => {
        //     this.model[item] = 1
        //   });
        // }
        // console.log(this.model);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            this.$emit("modelLoading",that.confirmLoading)
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              this.$emit("modelLoading",that.confirmLoading)
            })
          }
         
        })
      },
    }
  }
</script>